package com.djl.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.djl.ud.FlDao;
import com.djl.user.Fluser;

public class ClassAddServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		int parentId = 0;
		if(request.getParameter("parentId")!=null){
			parentId = Integer.parseInt(request.getParameter("parentId"));
		}
		String name = request.getParameter("className");
		
		
		Fluser fluser= new Fluser();
		fluser.setProjectId(parentId);
		fluser.setClassName(name);
		FlDao fd = new FlDao();
		boolean b = false;
		try {
			b=fd.insert(fluser);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(b){
			request.getRequestDispatcher("ClassServlet").forward(request,response);
		}else{
			request.getRequestDispatcher("no.jsp").forward(request,response);
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
	}

}
